package com.edou.system.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.edou.base.page.PageResult;
import com.edou.system.dao.ISysProgressLogDao;
import com.edou.system.dto.SysProgressLogCondition;
import com.edou.system.entity.SysProgressLog;
import com.edou.system.service.ISysProgressLogService;

/**
 * 操作进度日志
 * @creator
 * @create-time 2017/10/17 15:41:21
 * @email admin@edou.com
 * @company www.edou.com
 * @version 1.0
 */
@Service("sysProgressLogServiceImpl")
@Transactional(value = "transactionManager")
public class SysProgressLogServiceImpl implements ISysProgressLogService{

	@Resource(name = "sysProgressLogDaoImpl")
	private ISysProgressLogDao sysProgressLogDao;
	
	/**
	 * 查询所有操作进度日志
	 */
	public List<SysProgressLog> listSysProgressLogAll(){
		return sysProgressLogDao.listSysProgressLogAll();
	}

	/**
	 * 分页查询
	 * @param pageResult 分页对象
	 * @param condition 查询条件类
	 */
	public void listSysProgressLogByPage(PageResult<SysProgressLog> pageResult,SysProgressLogCondition condition){
		int rows = sysProgressLogDao.listSysProgressLogByPageCount(condition);
		pageResult.setRows(rows);

		RowBounds rowBounds = new RowBounds(pageResult.getCurrentPageIndex(),pageResult.getPageSize());
		List<SysProgressLog> list = sysProgressLogDao.listSysProgressLogByPage(rowBounds,condition);
		pageResult.setResult(list);
	}

	/**
	 * 根据条件查询
	 * @param condition 查询条件类
	 */
	public List<SysProgressLog> listSysProgressLogByCondition(SysProgressLogCondition condition){
		return sysProgressLogDao.listSysProgressLogByCondition(condition);
	}

	/**
	 * 根据ID查询
	 * @param id 主键
	 * @return 操作进度日志
	 */
	public SysProgressLog getSysProgressLogById(Long id){
		return sysProgressLogDao.getSysProgressLogById(id);
	}

	/**
	 * 新增
	 * @param item 操作进度日志
	 */
	public void add(SysProgressLog item){
		sysProgressLogDao.add(item);
	}
	
	/**
	 * 新增
	 * @param optKey 操作key
	 * @param content 日志内容
	 * @param finishFlag 是否完成标记位：0-未完成，1-已完成
	 */
	@Transactional(value = "transactionManager", propagation = Propagation.REQUIRES_NEW, isolation = Isolation.DEFAULT)
	public void add(String optKey,String content,Integer finishFlag) {
		SysProgressLog item = new SysProgressLog();
		item.setOptKey(optKey);
		item.setContent(content);
		item.setFinishFlag(finishFlag);
		
		sysProgressLogDao.add(item);
	}

	/**
	 * 修改
	 * @param item 操作进度日志
	 */
	public void update(SysProgressLog item){
		sysProgressLogDao.update(item);
	}

	/**
	 * 根据ID集合批量删除
	 * @param ids ID集合
	 */
	public void delByIds(Long[] ids){
		sysProgressLogDao.delByIds(ids);
	}

}

